23 template <class T
> string
toStr(const T
&x
){
24 stringstream s
; s
<< x
; return s
.str();
27 template <class T
> int toInt(const T
&x
){
28 stringstream s
; s
<< x
; int r
; s
>> r
; return r
;
31 #define For(i, a, b) for (int i=(a); i<(b); ++i)
32 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
33 #define D(x) cout << #x " = " << (x) << endl
35 const double EPS
= 1e-9;
36 int cmp(double x
, double y
, double tol
= EPS
){
37 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
43 int di
[] = {+0, +1, +1, +1};
44 int dj
[] = {+1, +1, +0, -1};
49 for (int j
= n
- 1; j
>= 0; --j
){
50 for (int i
= 0; i
< n
; ++i
){
55 for (int i
= n
- 1; i
>= 0; --i
){
56 for (int j
= 0; j
< n
; ++j
){
57 if (mat
[i
][j
] == '.') continue;
59 while (k
< n
and mat
[k
][j
] == '.') k
++;
60 swap(mat
[i
][j
], mat
[k
- 1][j
]);
65 for (int i
= 0; i
< n
; i
++){
66 for (int j
= 0; j
< n
; ++j
){
67 if (mat
[i
][j
] == '.') continue;
68 for (int d
= 0; d
< 4; ++d
){
69 int ni
= i
+ (k
- 1) * di
[d
];
70 int nj
= j
+ (k
- 1) * dj
[d
];
71 if (0 <= ni
and ni
< n
and 0 <= nj
and nj
< n
){
73 for (int p
= 0; p
< k
; ++p
){
74 if (mat
[i
+ p
* di
[d
] ][ j
+ p
* dj
[d
] ] != mat
[i
][j
]){
80 winners
|= (mat
[i
][j
] == 'R' ? 1 : 2);
96 }else if (winners
== 1){
98 }else if (winners
== 2){
100 }else if (winners
== 3){
103 printf("%s\n", s
.c_str());
109 for (int i
= 0; i
< T
; ++i
){
110 printf("Case #%d: ", i
+ 1);